package com.csair.irp.job.file.task;

import com.csair.irp.job.file.parser.autogateway.AutoGatewayFileParser;

/**
 * @Auther: liaolonglong
 * @Date: 2019/1/7 11:00
 * @Description:数据文件任务类型，存储路径和data_file_class、file_prefix的映射
 */
public enum TaskType {
    ET_AET("ET_DATA/${date}/AET", "ET", "AET", "AETFileParser"),
    ET_TCN("ET_DATA/${date}/TCN", "ET", "TCN", "AETFileParser"),
    ATK_TCN("ATK_DATA/${date}/TCN", "ATK", "TCN", null),
    ATK_ATK("ATK_DATA/${date}/ATK", "ATK", "ATK", null),
    AUTO_GATEWAY("GATEWAY_AUTOFILE/${date}", "支付网关", getBeanId(AutoGatewayFileParser.class));

    private String path;
    private String dataFileClass;
    private String filePrefix;
    private String beanId;

    TaskType(String path, String dataFileClass, String beanId) {
        this(path, dataFileClass, null, beanId);
    }

    TaskType(String path, String dataFileClass, String filePrefix, String beanId) {
        this.path = path;
        this.dataFileClass = dataFileClass;
        this.filePrefix = filePrefix;
        this.beanId = beanId;
    }

    public String getPath() {
        return path;
    }

    public String getDataFileClass() {
        return dataFileClass;
    }

    public String getFilePrefix() {
        return filePrefix;
    }

    public String getBeanId() {
        return beanId;
    }

    /**
     * 根据路径获取TaskType
     *
     * @param path
     * @return
     */
    public static TaskType getTaskTypeByPath(String path) {
        for (TaskType taskType : values()) {
            if (taskType.path.equalsIgnoreCase(path)) {
                return taskType;
            }
        }
        return null;
    }

    private static String getBeanId(Class<?> clazz) {
        String className = clazz.getSimpleName();
        return ((char)(className.charAt(0) + 32)) + className.substring(1);
    }
}
